Conversation
Updates Dart test template to use the first enum value for string properties with enums when generating test data, instead of always using the example value. This ensures generated test data is valid for properties with restricted enum values.
WalkthroughUpdates two test templates. In the Dart service test template, generated response-model test data for string properties now prefers the first enum value when an enum is present, falling back to the example otherwise; the response data map generation is updated accordingly. Test assertions for responses now check for a Map<String, dynamic> when a method defines multiple response models, otherwise they expect the specific model type. In the Flutter channel test template, the default account channel expectation changed from "account.*" to "account". No public APIs were changed. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Updated the Dart service test template to check for Map<String, dynamic> when multiple response models are present, improving test accuracy for methods with multiple possible response types.



Updates Dart test template to use the first enum value for string properties with enums when generating test data, instead of always using the example value. This ensures generated test data is valid for properties with restricted enum values.
What does this PR do?
This PR updates the Dart SDK test generation template (
service_test.dart.twig) to properly handle enum properties in generated test mocks. Previously, all string properties usedproperty.exampleas mock values, which could lead to invalid enum values causing "Bad state: No element" errors in model constructors likeMessage.fromMapwhen the example value didn't match any enum option.The change adds conditional logic for string properties:
property.enum[0]) as the mock valueproperty.exampleas beforeThis ensures that generated tests use valid enum values for properties with enums, preventing runtime errors during test execution.
Test Plan
regenerate sdk and run dart test
also push changes and ensure the GitHub Actions workflow for Dart SDK completes successfully with all tests passing. #1247
before:



after:
Have you read the Contributing Guidelines on issues?
Yes
Summary by CodeRabbit
New Features
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.